//201902104003邵潇漩
package bysj.service;

import bysj.dao.MajorDao;
import bysj.domain.Department;
import bysj.domain.Major;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;

public final class MajorService {
    private static MajorDao majorDao= MajorDao.getInstance();
    private static MajorService majorService=new MajorService();
    private MajorService(){}

    public static MajorService getInstance(){
        return majorService;
    }

    public Collection<Major> findAll() throws SQLException {
        return majorDao.findAll();
    }

    public Collection<Major> getAll(Department department) throws SQLException {
        Collection<Major> majors = new HashSet<Major>();
        for(Major major: majorDao.findAll()){
            if(major.getDepartment()==department){
                majors.add(major);
            }
        }
        return majors;
    }

    public Major find(Integer id) throws SQLException {
        return majorDao.find(id);
    }

    public boolean update(Major major) throws SQLException {
        return majorDao.update(major);
    }

    public boolean add(Major major) throws SQLException {
        return majorDao.add(major);
    }

    public boolean delete(Integer id) throws SQLException {
        return majorDao.delete(id);
    }

    public boolean delete(Major major) throws SQLException {
        return majorDao.delete(major);
    }
}